using Newtonsoft.Json;

namespace LeetCodeQuestionBank.Models
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int val = 0, ListNode next = null)
        {
            this.val = val;
            this.next = next;
        }

        public override bool Equals(object obj)
        {
            if (obj is ListNode node)
            {
                if (this.val == node.val)
                {
                    if (this.next == null && node.next == null)
                    {
                        return true;
                    }
                    if (this.next.Equals(node.next))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public override int GetHashCode()
        {
            return this.val.GetHashCode();
        }

        public override string ToString()
        {
            return this.ToString(ListNodeExtend.LISTNODE_DEFAULT_INTERVAL);
        }
        public string ToString(string interval = ListNodeExtend.LISTNODE_DEFAULT_INTERVAL)
        {
            if (this == null)
            {
                return string.Empty;
            }
            string value = this.val.ToString();
            if (this.next != null)
            {
                value = value + interval + this.next.ToString(interval);
            }
            return value;
        }
    }
}
